﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml;
using CFM.DAL;
using CFM.Common;

namespace CFM
{
    public partial class frmConfig : Form
    {
        public XmlDocument _doc = null;
        public frmConfig()
        {
            InitializeComponent();
            _doc = new XmlDocument();
            _doc.Load(PathHelper.ConfigFolder + "\\Config.xml");
            Loaddata();
        }
        private void Loaddata()
        {
            if (_doc != null)
            {
                XmlNode node = _doc.SelectSingleNode("/connect");
                txtSvname.Text = node.Attributes["server"].Value;
                txtUser.Text = node.Attributes["userid"].Value;
                txtPassword.Text = node.Attributes["userpass"].Value;
            }
        }

        private void btnsave_Click(object sender, EventArgs e)
        {
            if (txtSvname.Text == "" || txtUser.Text == "" || txtPassword.Text == "")
                MessageBox.Show("không được để tróng");

            XmlNode node = _doc.SelectSingleNode("/connect");
            node.Attributes["server"].Value = txtSvname.Text.Trim();
            node.Attributes["userid"].Value = txtUser.Text.Trim();
            node.Attributes["userpass"].Value = txtPassword.Text.Trim();
            _doc.Save(PathHelper.ConfigFolder + "\\Config.xml");
            MessageBox.Show("Lưu thành công");
        }

        private void btnDong_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}
